package conf

import (
	"flag"
	"time"

	"github.com/kylelemons/go-gypsy/yaml"
)

var config string
var yamlRead *yaml.File

func init() {
	flag.StringVar(&config, "c", "config.yaml", "default config path")
	flag.Parse()
	var err error
	yamlRead, err = yaml.ReadFile(config)
	if err != nil {
		panic(err)
	}
}

func GetCloudDataConf() string {
	cloud_data, err := yamlRead.Get("databases.cloud_data")
	if err != nil {
		panic(err.Error())
	}
	return cloud_data
}

func GetSiteConf() string {
	site, err := yamlRead.Get("databases.site")
	if err != nil {
		panic(err.Error())
	}
	return site
}

func GetHostPort() string {
	host, _ := yamlRead.Get("http.host")
	port, _ := yamlRead.Get("http.port")
	return host + ":" + port
}

func GetIntervalMinute() time.Duration {
	minute, err := yamlRead.GetInt("interval.minute")
	if err != nil || minute == 0 {
		return time.Duration(30)
	}
	return time.Duration(minute)
}
